<?php
$this->breadcrumbs=array(
	'Contents'=>array('index'),
	'Manage',
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('content-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<div class="contentwrapper"><!--Content wrapper-->
<div class="alert alert-info">
    <button type="button" class="close" data-dismiss="alert">&times;</button>
    <p><strong>
        <span class="icon16  brocco-icon-mic"></span>
        <?php echo t('You may optionally enter a comparison operator at the beginning of each of your search values to specify how the comparison should be done.','search'); ?>
    </strong></p>
</div>

<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button btn')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
    'filter'=>$model,
    'type'=>'striped bordered',
    'dataProvider' => $model->search(),
    'template' => "{pager}\n{items}\n{extendedSummary}\n{pager}",
    'id'=>'content-grid',
    'responsiveTable'=>true,
    'bulkActions' => array(
        'actionButtons' => array(
            array(
                'buttonType' => 'button',
                'type' => 'primary',
                'size' => 'small',
                'label' => t('Active','fcms'),
                'click' => 'js:function(checked){
                     var values = [];
                     checked.each(function(){
                         values.push($(this).val());
                     });
                    bootbox.confirm("'.t('Are you sure that you want to activate the selected contents ?','fcms').'", function(result) {
                  if(result){
                  $.ajax({
                     url:"'.url('/content/batchSwitchStatus').'",
                     cache:false,
                     type:"POST",
                     data: {ids:values.join(","),type:"active",'.csrfTokenName().':"'.csrfToken().'"},
                     success:function(data){
                         $("#content-grid").yiiGridView("update");
                        }
                        });
                      }
                    });
            }',
            ),
            array(
                'buttonType' => 'button',
                'type' => 'primary',
                'size' => 'small',
                'label' => t('Deactivate','fcms'),
                'click' => 'js:function(checked){
                     var values = [];
                     checked.each(function(){
                         values.push($(this).val());
                     });
                     bootbox.confirm("'.t('Are you sure that you want to inactivate the selected contents ?','fcms').'", function(result) {
                  if(result){
                  $.ajax({
                     url:"'.url('/content/batchSwitchStatus').'",
                     cache:false,
                     type:"POST",
                     data: {ids:values.join(","),type:"inactive",'.csrfTokenName().':"'.csrfToken().'"},
                     success:function(data){
                         $("#content-grid").yiiGridView("update");
                        }
                        });
                      }
                    });
            }'
            ),
            array(
                'buttonType' => 'button',
                'type' => 'primary',
                'size' => 'small',
                'label' => t('Trash','fcms'),
                'click' => 'js:function(checked){
                     var values = [];
                     checked.each(function(){
                         values.push($(this).val());
                     });
                    bootbox.confirm("'.t('Are you sure that you want to move the selected contents to Trash ?','fcms').'", function(result) {
                  if(result){
                  $.ajax({
                     url:"'.url('/content/batchSwitchStatus').'",
                     cache:false,
                     type:"POST",
                      data: {ids:values.join(","),type:"deleted",'.csrfTokenName().':"'.csrfToken().'"},
                     success:function(data){
                         $("#content-grid").yiiGridView("update");
                        }
                        });
                      }
                    });
                }'
            ),
            array(
                'buttonType' => 'button',
                'type' => 'primary',
                'size' => 'small',
                'label' => t('Delete','fcms'),
                'click' => 'js:function(checked){
                     var values = [];
                     checked.each(function(){
                         values.push($(this).val());
                     });
                    bootbox.confirm("'.t('Are you sure that you want to permanently delete the selected contents ?','fcms').'", function(result) {
                  if(result){
                  $.ajax({
                     url:"'.url('/content/batchDelete').'",
                     cache:false,
                     type:"POST",
                     data: {ids:values.join(","),'.csrfTokenName().':"'.csrfToken().'"},
                     success:function(data){
                         $("#content-grid").yiiGridView("update");
                        }
                        });
                      }
                    });
                }'
            ),
        ),
        // if grid doesn't have a checkbox column type, it will attach
        // one and this configuration will be part of it
        'checkBoxColumnConfig' => array(
            'name' => 'id',
            'checkBoxHtmlOptions'=>array('class'=>'nostyle')
        ),
    ),
	'columns'=>array(
        array(
            'class'=>'bootstrap.widgets.TbRelationalColumn',
            'name' => 'title',
            'filter'=> $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                //'name'=>'title',
                'id'=>'titleAutoComplete',
                'model'=>$model,
                'attribute'=>'title',
                'sourceUrl'=>url('/content/autocomplete'),
                'options'=>array(
                    'minLength'=>'2',
                ),
                'htmlOptions'=>array(
                    'size'=>'36'
                ),
            ), true),
            'url' => $this->createUrl('content/relational'),
            'value'=> array($model,'renderTitle'),
            'type'=>'raw',
            'htmlOptions'=>array('style'=>'text-align:left'),
        ),
        array(
            'class' => 'bootstrap.widgets.TbEditableColumn',
            'name'=>'category_id',
            'sortable'=>true,
            'value'=>'$data->category->name',
            'filter'=>Category::getDataCategory(false),
            'editable' => array(
                'type'=>'select',
                'source'=>Category::getDataCategory(),
                'url' => $this->createUrl('content/editable'),
                'placement' => 'right',
                'inputclass' => 'span3',
                'options'=>array(
                    'params'=>array(
                        csrfTokenName()=>csrfToken(),
                    )
                ),
            )
        ),
        //'sub_title',
        array(
            'class' => 'bootstrap.widgets.TbEditableColumn',
            'name' => 'type',
            'value'=>'ucfirst($data->type)',
            'filter'=>contentType(),
            'sortable'=>true,
            'editable' => array(
                'type'=>'select',
                'source'=>contentType(),
                'url' => $this->createUrl('content/editable'),
                'placement' => 'right',
                'inputclass' => 'span3',
                'options'=>array(
                    'params'=>array(
                        csrfTokenName()=>csrfToken(),
                    )
                ),
            )),
        array(
            'class' => 'bootstrap.widgets.TbEditableColumn',
            'name' => 'status',
            'value'=>'ucfirst($data->status)',
            'filter'=>contentStatus(),
            'sortable'=>true,
            'editable' => array(
                'type'=>'select',
                'source'=>contentStatus(),
                'url' => $this->createUrl('content/editable'),
                'placement' => 'right',
                'inputclass' => 'span3',
                'options'=>array(
                    'params'=>array(
                        csrfTokenName()=>csrfToken(),
                    )
                ),
            ),
        ),
        array(
            'name' => 'activate_date',
            'value'=>'renderTime($data->activate_date)',
            'filter'=> $this->widget('bootstrap.widgets.TbDateRangePicker', array(
                //'name'=>'title',
                //'id'=>'Content_active_date_filter',
                'model'=>$model,
                'attribute'=>'activate_date_range',
                'options' => array(
                    'format'=>locale()->getDateFormat('short'),
                ),
                'htmlOptions'=>array(
                    'size'=>'36'
                ),
            ), true),
            'type'=>'raw',
            ),
        array(
            'class'=>'bootstrap.widgets.TbToggleColumn',
            'toggleAction'=>'content/toggle',
            'filter'=>array('1'=>t('Yes','content'),'0'=>t('No','content')),
            'name' => 'is_hot',
            'headerHtmlOptions'=>array('width'=>'30px')
        ),
        array(
            'class'=>'bootstrap.widgets.TbToggleColumn',
            'toggleAction'=>'content/toggle',
            'filter'=>array('1'=>t('Yes','content'),'0'=>t('No','content')),
            'name' => 'sticky',
            'headerHtmlOptions'=>array('width'=>'30px')
        ),
        array(
            'name'=>'num_views',
            'filter'=>false,
            'headerHtmlOptions'=>array('width'=>'30px')
        ),
        array(
            'name'=>'id',
            'headerHtmlOptions'=>array('width'=>'30px')
        ),
		/*
		'description',
		'content',
		'author',
		'meta_keyword',
		'meta_description',
		'meta_robots',
		'meta_revisit_after',
		'image',
		'status',
		'created_date',
		'created_user_id',
		'created_user_name',
		'updated_date',
		'updated_user_id',
		'updated_user_name',
		'activate_user_id',
		'activate_user_name',
		'activate_date',
		'allow_comment',
		'num_comments',
		'ordering',
		'show_date',
		'language',
		*/
        array(
            'class'=>'bootstrap.widgets.TbButtonColumn',
            'template' => '{update}{delete}',
        ),
	),
)); ?>
</div><!-- End #Contenwapper -->